package com.dayuan.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.dayuan.bean.Goods;
import com.dayuan.dao.GoodsMapper;

@Service
public class GoodsService {
	private static Logger logger = LoggerFactory.getLogger(GoodsService.class);

	@Resource
	private GoodsMapper goodsMapper;

	/**
	 * 通过商品名称关键字 模糊查询商品信息集合
	 * 
	 * @param goodsName
	 * @return
	 */
	public List<Goods> selectGoodsByParam(String goodsName) {
		return goodsMapper.selectGoodsByParam(goodsName);
	}

	/**
	 * 通过商品id 精确查询商品信息
	 * 
	 * @param goodsId
	 * @return
	 */
	public Goods selectGoodsById(Long goodsId) {
		return goodsMapper.selectGoodsById(goodsId);
	}

	/**
	 * 通过商家id 查询商品信息集合
	 * 
	 * @param merchantId
	 * @return
	 */
	public List<Goods> selectGoodsByMerchantId(Integer merchantId) {
		return goodsMapper.selectGoodsByMerchantId(merchantId);
	}

	/**
	 * 查询总行数
	 * 
	 * @return
	 */
	public int selectCountGoodsByParam() {
		return goodsMapper.selectCountGoodsByParam();
	}

	/**
	 * 按页查询
	 * 
	 * @param startIndex
	 * @param pageNum
	 * @return
	 */
	public List<Goods> selectCountGoodsByParamForPage(@Param("startIndex") Integer startIndex,
			@Param("pageNum") Integer pageNum) {
		return goodsMapper.selectCountGoodsByParamForPage(startIndex, pageNum);
	}

	/**
	 * 商家查询商品，支持商品名模糊查询、商品id查询、查询所有
	 * 
	 * @param good
	 * @return
	 */
	public List<Goods> sellerSelectGoods(Goods goods, Integer startIndex, Integer pageNum) {
		List<Goods> goodsList = goodsMapper.selectSellerGoods(goods, startIndex, pageNum);
		return goodsList;
	}

	public int selcetTotal(Goods goods) {
		int tatol = goodsMapper.total(goods);
		return tatol;
	}

	/**
	 * 根据不同条件，删除商品
	 * 
	 * @param goods
	 * @return
	 */
	public int deleteGoodsByParam(Goods goods) {
		int count = goodsMapper.deleteGoodsByParam(goods);
		return count;
	}

	/**
	 * 动态 添加 商品
	 * 
	 * @param goods
	 * @return
	 */
	public int insertGoodsSelective(Goods goods) {
		int count = goodsMapper.insertGoodsSelective(goods);
		return count;
	}

	/**
	 * 动态 更改 商品信息
	 * 
	 * @param goods
	 * @return
	 */
	public int updateGoodsByParams(Goods goods) {
		int count = goodsMapper.updateGoodsByParams(goods);
		return count;
	}

}
